package com.xt.purchasingsystem.utils;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

@ToString
@Getter
@Setter
@NoArgsConstructor
public class MySQLPageBean {

    /**
     * 页码大小
     */
    private int pageSize;
    /**
     * 当前页码
     */
    private int currNo;
    /**
     * 总行数
     */
    private int rowCount;
    /**
     * 总页数
     */
    private int pageCount;
    /**
     * 页面显示的数据集合
     */
    private List pageList;

    public MySQLPageBean(int pageSize, int currNo, int rowCount) {
        super();
        this.pageSize = pageSize;
        this.currNo = currNo;
        this.rowCount = rowCount;
        //求出总页数
        if (this.rowCount % this.pageSize == 0) {
            this.pageCount = this.rowCount / this.pageSize;
        } else {
            this.pageCount = this.rowCount / this.pageSize + 1;
        }
        //判断是否达到最后一页

        //当前页码小于
        if (this.currNo > this.pageCount) {
            this.currNo = this.pageCount;
        }
        if (this.currNo < 1) {
            this.currNo = 1;
        }
    }

    public int getStart() {
        //当前页码减页码大小
        return (this.currNo - 1) * this.pageSize;
    }

}
